/*包含多个由action触发直接更新状态的方法的对象*/
import {ADD_TODO, CLEAR_ALL_COMPLETED, DELETE_TODO, RECEIVE_TODOS, SELECT_ALL_TODOS} from "./mutation-types";

export default {
  /*这里是为了使ADD_TODO这个名字成为一个变量*/
  [ADD_TODO](state,{item}){
    state.todos.unshift(item)
  },
  [DELETE_TODO](state,{index}){
    state.todos.splice(index,1)
  },
  [SELECT_ALL_TODOS](state,{isCheck}){
    state.todos.forEach(todo => todo.complete = isCheck)
  },
  [CLEAR_ALL_COMPLETED](state){
    state.todos = state.todos.filter(todo => !todo.complete)
  },

  [RECEIVE_TODOS](state, {todos}){
    state.todos = todos
  }
}
